﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Artech.PetShop.Infrastructures.Interface;
using System.Web;

namespace Artech.PetShop.Infrastructures
{
    public class QueryStringResolverService : IQueryStringResolverService
    {
        #region IQueryStringResolverService Members

        public string GetValue(string key)
        {
            if(string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("key");
            }

            var keys = HttpContext.Current.Request.QueryString.AllKeys.Where(item => string.Equals(item, key, StringComparison.InvariantCultureIgnoreCase));
            if (keys.Count() == 0)
            {
                return string.Empty;
            }

            return HttpContext.Current.Request.QueryString[keys.ToArray<string>()[0]];
        }

        #endregion
    }
}
